<?php
/**
 * Created by PhpStorm.
 * User: 王溪
 * Date: 2019/4/3
 * Time: 22:33
 * 权限管理控制器
 */

namespace app\index\controller;


use think\Controller;

class Rbac extends Controller
{
    public $user_id = 1;

    /**
     * 查看用户权限列表
     */
    public function index()
    {
        $data = db('user')->find();

        //dump($data);
    }
    /**
     * 添加用户关系表
     */
    public function add_role()
    {
        //查看所有角色
        $role = db('role')->select();
        //查看当前用户的角色
        $user_role = db('user_role')->where('user_id',$this->user_id)->find();

        if($user_role){
            $user_role['role_id'] = explode(',',$user_role['role_id']);
        }
       // dump($user_role);die;


        //dump($role);die;
        $this->assign('role',$role);
        $this->assign('user_role',$user_role);
        return $this->fetch();
    }

    /**
     * 添加用户角色关系表
     */
    public function insert_role()
    {
        $role_id = input('role_id/a');
        $role_id_str = implode(',',$role_id);
        db('user_role')->where('user_id',$this->user_id)->update(['role_id'=>$role_id_str]);
        //echo 'end';
        $this->success('success','index/rbac/add_role');

        //dump($role_id);
    }



}